
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    mp.clear();
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      mp[x]++;
    }

    long long same = 0;
    for (auto it : mp) {
      int v = it.second;
      same += (long long)v * (v - 1) / 2;
    }
    cout << (long long)n * (n - 1) / 2 - same << endl;
  }

  return 0;
}